#!/bin/bash
set -e
# rm -rf build
os=$(uname)
if [ "$os" = "Linux" ]; then
    arch_type=$(uname -m)
    if [ "$arch_type" = "aarch64" ];then
        export LOCAL_CXX_LIBS_PATH=$PWD/middlewares/linux-aarch64
    elif [ "$arch_type" = "x86_64" ];then
        export LOCAL_CXX_LIBS_PATH=$PWD/middlewares/linux-x86
    else
        echo "unknown machine type"
        exit 1
    fi
    if [ ! -d $LOCAL_CXX_LIBS_PATH ];then
        echo LOCAL_CXX_LIBS_PATH:$LOCAL_CXX_LIBS_PATH not exist
        exit 1
    fi
    cmake -B build -DUNIT_TEST=ON
elif [[ "$os" == *"MINGW"* ]]; then
    export LOCAL_CXX_LIBS_PATH=`cygpath -w $PWD/middlewares/win`
    if [ ! -d $LOCAL_CXX_LIBS_PATH ];then
        echo LOCAL_CXX_LIBS_PATH:$LOCAL_CXX_LIBS_PATH not exist
        exit 1
    fi
    cmake -B build -G"MinGW Makefiles" -DUNIT_TEST=ON
else
    echo "unknown os"
    exit 1
fi

cmake --build build -j$(nproc)
# ctest --test-dir build -V
ctest --test-dir build
